﻿using Base.Infrastructure.Dto.Request.Error;
using Base.Infrastructure.EFCore.MySql;
using Base.Infrastructure.IOC;
using Base.Infrastructure.Tools;
using Base.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Base.Service.Instance
{
    public class ErrorService : BaseService, IErrorService
    {
        private readonly ErrorIOC _errorIOC;

        public ErrorService(ErrorIOC errorIOC)
        {
            _errorIOC = errorIOC;
        }

        /// <summary>
        /// 记录行为日志
        /// </summary>
        /// <param name="dto"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void AddActionLog(ErrorRequestDto dto)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 记录错误日志
        /// </summary>
        /// <param name="dto"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void AddError(ErrorRequestDto dto)
        {
            ErrorLog errorLog = new ErrorLog()
            {
                Eid = Config.GUID(),
                Eapi = dto.url,
                EcreateTime = DateTime.Now.ToString(),
                Eip = dto.ip,
                Emessage = dto.message,
                Eparams = dto.paras,
                Euid = dto.uid
            };
            _errorIOC._errorLog.Add(errorLog);
            int result = _errorIOC._errorLog.SaveChanges();
        }
    }
}
